package com.zhw.controller;

import com.zhw.pojo.dto.ChanceQueryDTO;
import com.zhw.pojo.PageBean;
import com.zhw.pojo.Result;
import com.zhw.pojo.entry.SaleChance;
import com.zhw.service.ChanceService;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("chance")
public class ChanceController {


    @Autowired
    ChanceService chanceService;


    @Autowired
    HttpServletRequest request;
    @Autowired
    HttpServletResponse response;

    @GetMapping
    public Result page(ChanceQueryDTO chanceQueryDTO){
        log.info("分页查询营销信息：{}",chanceQueryDTO);
        PageBean pb=chanceService.page(chanceQueryDTO);
        return Result.success(pb);
    }


    @PostMapping
    public Result save(@RequestBody SaleChance saleChance){
        log.info("添加一个新的营销计划：{}",saleChance);
        chanceService.save(saleChance);

        return Result.success();
    }


    @GetMapping("/getById")
    public Result getByID(Integer id){
        log.info("查询到营销计划ID：{}",id);
        SaleChance saleChance=chanceService.getByID(id);
        return Result.success(saleChance);
    }

    @PutMapping
    public Result update(@RequestBody SaleChance saleChance){
        log.info("修改一个营销计划：{}",saleChance);
        chanceService.update(saleChance);
        return Result.success();
    }


    @DeleteMapping
    public Result deleteByID(Integer id){
        log.info("删除ID为：{}的营销计划：",id);
        chanceService.deleteByID(id);
        return Result.success();
    }

    @PutMapping("updateResult")
    public Result updateResult(@RequestBody SaleChance saleChance){
        log.info("修改状态为：{}",saleChance);
        chanceService.updateResult(saleChance);
        return Result.success();
    }
}
